//
//  ViewController.m
//  rsaDemo
//
//  Created by chen on 2017/8/2.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "ViewController.h"
#import "RSAEncryptor.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    RSAEncryptor *rsa = [[RSAEncryptor alloc] init];
    
    NSString *publicKeyPath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"];
    NSLog(@"public key: %@", publicKeyPath);
    [rsa loadPublicKeyFromFile:publicKeyPath];
    
    

    NSString *privateKeyPath = [[NSBundle mainBundle] pathForResource:@"private_key" ofType:@"p12"];
    NSLog(@"private key: %@", privateKeyPath);
    [rsa loadPrivateKeyFromFile:privateKeyPath password:@""]; //密码不对就会崩溃
    
    
    
    NSString *securityText = @"hello world";
    NSString *encryptedString = [rsa rsaEncryptString:securityText];
    NSLog(@"加密结果: %@", encryptedString);
    
 
    NSString *result = [rsa rsaDecryptString:encryptedString];
    NSLog(@"解密结果: %@", result);

}








@end
